new Vue({
	el: '.vuedata',
	data() {
		return {
			ip: IPCMS,
			url: "/index.php/api/Carousels",
			listurl: "/index.php/api/Pages/normal",
			noteurl: "/index.php/api/Notes",
			columnurl: "/index.php/api/categries",
			mark: 0, //比对图片索引的变量
			result: [], //banner
			note: [], //一条公告
			list: [], //新闻列表
			page: 1, //文章页数
			flag: true,
			longtext: "加载中",
			columnArrId: "",
			columnArr: [], //栏目数据
			isshow: false, //是否显示栏目弹窗

		}
	},
	methods: {
		//页面跳转
		htmlgo(url) {
			window.location.href = "news.html?id=" + url;
		},
		//跳转到公告页面
		notego(uid) {
			if(uid == "more") {
				window.location.href = "notice.html";

			} else {
				window.location.href = "nots.html?id=" + uid;

			}
		},
		/**
		 * banner幻灯片
		 */
		autoPlay() {
			this.mark++;
			if(this.mark === this.result.length) { //当遍历到最后一张图片置零
				this.mark = 0
			}
		},
		play() {
			setInterval(this.autoPlay, 2500)
		},
		change(i) {
			this.mark = i
		},
		/**
		 * 获取一条公告数据 
		 */
		noteData() {
			var http = this.ip + this.noteurl;
			this.$http.jsonp(http, {
				params: {
					"per_page": 1
				}
			}).then(res => {
				var body = res.body;
				this.note = body.result;
				//				this.play();
				//				console.log(this.note);
				//				console.log(JSON.stringify(this.note));
				//				console.log(this.note[0].title);
			}).catch(res => {
				console.log("请求出错");
			})
		},
		/**
		 * 获取banner数据 
		 */
		getData() {
			var http = this.ip + this.url;
			this.$http.jsonp(http).then(res => {
				var body = res.body;
				this.result = body.result;
				this.play();
			}).catch(res => {
				console.log("请求出错");
			})
		},
		/**
		 * 获取文章列表
		 */
		listData() {
			var http = this.ip + this.listurl;
			this.$http.jsonp(http, {
				params: {
					"page": this.page,
					"cid": this.columnArrId,
					"per_page": 10
				}
			}).then(res => {
				var body = res.body;
//				console.log(body);
				var data = body.result;
				if(data.length > 0) {
					//					data.forEach(e=>{
					//						e.add_time=this.formartDate(e.add.time);
					//					});
					if(this.list.length == 0||this.list.length<10) {
						this.list = data;
					} else {
						this.list = this.list.concat(data);
					}
					this.flag = true;
					this.longtext = "加载更多";
				} else {
					this.flag = false;
					this.longtext = "没有更多了";
				}

			}).catch(res => {
				console.log("请求出错");
				this.flag = false;
				this.longtext = "请求错误，请刷新重试";
			})
		},
		/**
		 * 加载更多
		 */
		onloading() {
			if(this.flag) {
				this.flag = false;
				this.longtext = "加载中";
				this.page = this.page + 1;
				console.log("ccc");
				//			            modal.toast({ message: 'loading', duration: 1 })
				setTimeout(() => {
					this.listData();
				}, 1500)
			}
			console.log("执行");
		},
		//点击弹出栏目板块
		column() {
			this.isshow = true;
		},
		//栏目板块点击取消
		hideFilter() {
			this.isshow = false;
		},
		//栏目版块点击确定
		confirmSelectFun() {
			this.list = [];
			var b = [];
			this.columnArr.forEach(t => {
				if(t.children && t.children.length > 0) {
					t.children.forEach(e => {
						if(e.status) {
							b.push(e.id);
						}
					})
				}
			});
			pub.sessionsetdata(this.columnArr);
			this.columnArrId = b.toString();
			this.listData();
			this.isshow = false;
		},
		//点击，状态取反
		selectIds(index, t) {
			var con = this.columnArr[index];
			t.status = !t.status;
			Vue.set(this.columnArr, index, con);

		},
		//获取栏目数据
		getColumn() {
			var http = this.ip + this.columnurl;
			this.$http.jsonp(http).then(res => {
				var body = res.body;
				this.columnArr =body.result;
				this.columnArr.forEach(e => {
					if(e.children && e.children.length > 0) {
						e.children.forEach(t => {
							t.status = false;
						})
					}
				});
				this.columnArr=pub.sessiondata(this.columnArr);
				this.confirmSelectFun();
//				console.log(JSON.stringify(this.columnArr));
			}).catch(res => {
				console.log("请求出错");
			})

		},
		//-----------------------------------------
		timestampToTime(timestamp) {
			return pub.timestampToTime(timestamp);

		},
		//字符串过长截取
		subst(data) {
			var num = 12;
			return pub.substdata(data, num);
		},
	},
	created() {
		this.getData();
//		this.listData();
		this.noteData();
		this.getColumn();
	},

})